home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
xintro18.zip
/
XINTRO.TXT
< prev
Wrap
Text File
|
1993-11-25
|
23KB
|
570 lines
Title: INTRODUCTION TO MODE X (XINTRO.TXT)
Version: 1.8
Author: Robert Schmidt <robert@stud.unit.no>
Copyright: (C) 1993 of Ztiff Zox Softwear - refer to Status below.
Last revision: 25-Nov-93
Figures: 1. M13ORG - memory organization in mode 13h
2. MXORG - memory organization in unchained modes
The figures are available both as 640x480x16 bitmaps
(in GIF format), and as 7-bit ASCII text (ASC) files.
C sources: 1. LIB.C v1.2 - simple graphics library for planar,
256-color modes - optionally self-testing.
Excerpts from the source(s) appear in this article.
Whenever there are conflicts, the external source file(s)
are correct (or, at least, newest), _not_ the excerpts
provided here.
Status: This article, its associated figures and source listings
named above, are all donated to the public domain.
Do with it whatever you like, but give credit where
credit is due. I would prefer it if this archive was
distributed in its entirety, including the files
mentioned above.
The standard disclaimer applies.
Index: 0. ABSTRACT
1. INTRODUCTION TO THE VGA AND ITS 256-COLOR MODE
2. GETTING MORE PAGES AND PUTTING YOUR FIRST PIXEL
3. THE ROAD FROM HERE
4. BOOKS ON THE SUBJECT
5. BYE - FOR NOW
0. ABSTRACT
This text gives a fairly basic, yet technical, explanation to what, why
and how Mode X is. It first tries to explain the layout of the VGA
memory and the shortcomings of the standard 320x200 256-color mode,
then gives instructions on how one can progress from mode 13h to a
multipage, planar 320x200 256-color mode, and from there to the
quasi-standard 320x240 mode, known as Mode X.
A little experience in programming the standard VGA mode 13h
(320x200 in 256 colors) is assumed. Likewise a good understanding of
hexadecimal notation and the concepts of segments and I/O ports is
assumed. Keep a VGA reference handy, which at least should have
definitions of the VGA registers at bit level.
Throughout the article, a simple graphics library for unchained (planar)
256-color modes is developed. The library supports the 320x200 and
320x240 modes, active and visible pages, and writing and reading
individual pixels.
1. INTRODUCTION TO THE VGA AND ITS 256-COLOR MODE
Since its first appearance on the motherboards of the IBM PS/2 50, 60
and 80 models in 1987, the Video Graphics Array has been the de facto
standard piece of graphics hardware for IBM and compatible personal
computers. The abbreviation, VGA, was to most people synonymous with
acceptable resolution (640x480 pixels), and a stunning rainbow of colors
(256 from a palette of 262,144), at least compared to the rather gory
CGA and EGA cards.
Sadly, to use 256 colors, the VGA BIOS limited the users to 320x200
pixels, i.e. the well-known mode 13h. This mode has one good and one
bad asset. The good one is that each one of the 64,000 pixels is easily
addressable in the 64 Kb video memory segment at 0A000h. Simply calculate
the offset using this formula:
offset = (y * 320) + x;
Set the byte at this address (0A000h:offset) to the color you want, and
the pixel is there. Reading a pixel is just as simple: just read the
corresponding byte. This was heaven, compared to the havoc of planes and
masking registers needed in 16-color modes. Suddenly, the distance from a
graphics algorithm on paper to an implemented graphics routine in assembly
was cut down to a fraction. The results were impressively fast, too!
The bad asset is that mode 13h is also limited to only one page, i.e.
the VGA can hold only one screenful at any one time (plus 1536 pixels, or
about four lines). Most 16-color modes let the VGA hold more than one page,
and this enables you to show one of the pages to the user, while drawing on
another page in the meantime. Page flipping is an important concept in making
flicker free animations. Nice looking and smooth scrolling is also almost
impossible in mode 13h using plain VGA hardware.
Now, the alert reader might say: "Hold on a minute! If mode 13h enables
only one page, this means that there is memory for only one page. But I
know for a fact that all VGAs have at least 256 Kb RAM, and one 320x200
256-color page should consume only 320*200=64000 bytes, which is less
than 64 Kb. A standard VGA should room a little more than four 320x200
pages!" Quite correct, and to see how the BIOS puts this limitation on
mode 13h, I'll elaborate a little on the memory organization of the VGA.
The memory is separated into four bit planes. The reason for this stems
from the EGA, where graphics modes were 16-color. Using bit planes, the
designers chose to let each pixel on screen be addressable by a single
bit in a single byte in the video segment. Assuming the palette has
not been modified from the default, each plane represent one of the EGA
primary colors: red, green, blue and intensity. When modifying the bit
representing a pixel, the Write Plane Enable register is set to the
wanted color. Reading is more complex and slower, since you can
only read from a single plane at a time, by setting the Read Plane
Select register. Now, since each address in the video segment can
access 8 pixels, and there are 64 Kb addresses, 8 * 65,536 = 524,288
16-color pixels can be accessed. In a 320x200 16-color mode, this makes
for about 8 (524,288/(320*200)) pages, in 640x480 you get nearly 2
(524,288/(640*480)) pages.
In a 256-color mode, the picture changes subtly. The designers decided
to fix the number of bit planes to 4, so extending the logic above to 8
planes and 256 colors does not work. Instead, one of their goals was to
make the 256-color mode as easily accessible as possible. Comparing the
8 pixels/address in 16-color modes to the 1-to-1 correspondence of
pixels and addresses of mode 13h, one can say that they have
succeeded, but at a certain cost. For reasons I am not aware of, the
designers came up with the following effective, but memory-wasting
scheme:
The address space of mode 13h is divided evenly across the four bit
planes. When an 8-bit color value is written to a 16-bit address in the
VGA segment, a bit plane is automatically selected by the 2 least
significant bits of the address. Then all 8 bits of the data is written
to the byte at the 16-bit address in the selected bitplane (have a look at
figure 1). Reading works exactly the same way. Since the bit planes are so
closely tied to the address, only every fourth byte in the video memory is
accessible, and 192 Kb of a 256 Kb VGA go to waste. Eliminating the
need to bother about planes sure is convenient and beneficial, but to
most people the loss of 3/4 of the total VGA memory sounds just hilarious.
To accomodate this new method of accessing video memory, the VGA
designers introduced a new configuration bit called Chain-4, which
resides as bit number 3 in index 4 of the Sequencer. In 16-color modes,
the default state for this bit is off (zero), and the VGA operates as
described earlier. In the VGA's standard 256-color mode, mode 13h, this
bit is turned on (set to one), and this turns the tieing of bit
planes and memory address on.
In this state, the bit planes are said to be chained together, thus mode
13h is often called a _chained mode_.
Note that Chain-4 in itself is not enough to set a 256-color mode -
there are other registers which deals with the other subtle changes in
nature from 16 to 256 colors. But, as we now will base our work with
mode X on mode 13h, which already is 256-color, we won't bother about
these for now.
2. GETTING MORE PAGES AND PUTTING YOUR FIRST PIXEL
The observant reader might at this time suggest that clearing the
Chain-4 bit after setting mode 13h will give us access to all 256 Kb of
video memory, as the two least significant bits of the byte address
won't be `wasted' on selecting a bit plane. This is correct. You might
also start feeling a little uneasy, because something tells you that
you'll instantly loose t